package com.gxa.controller.HhyController;

import com.gxa.entity.Subscribe;
import com.gxa.mapper.MakeMapper;
import com.gxa.service.MakeService;
import com.gxa.utils.R;
import com.gxa.vo.*;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Api(tags="患者预约挂号接口")
@RestController
public class MakeController {

    @Autowired
    private MakeService makeService;

    @ApiOperation(value = "患者挂号预约类型选择接口",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回xx详细信息",examples = @io.swagger.annotations.Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("pre:sel")
    @GetMapping("/make/typeMake")
    public R typeMake(){
        List<Integer> list = this.makeService.selectSubType();

//        list.add("门诊");
//        list.add("核酸");
//        list.add("体检");

        return R.ok().put("data",list);
    }


    @ApiOperation(value = "科室选择接口",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回xx详细信息",examples = @io.swagger.annotations.Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("pre:sel")
    @GetMapping("/make/departmentMake")
    public R departmentMake(@ApiParam(name="selectFormat-为参数名",value = "预约参数--这里写参数描述",required = true)Integer id) {
        List<IdDepartmentVo> list = this.makeService.selectBySubType(id);
        return R.ok().put("data",list);
    }

    @ApiOperation(value = "医生选择类型选择接口",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回xx详细信息",examples = @io.swagger.annotations.Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("pre:sel")
    @PostMapping("/make/doctorAndType")
    public R doctorAndType(@ApiParam(name="selectFormat-为参数名",value = "预约参数--这里写参数描述",required = true)@RequestBody IdDepartmentVo idDepartmentVo) {
        List<MakeByDepartVo> list = this.makeService.selectByDepart(idDepartmentVo);
        return R.ok().put("data",list);
    }


    @ApiOperation(value = "患者挂号接口",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回xx详细信息",examples = @io.swagger.annotations.Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("pre:add")
    @PostMapping("/make/patientMake")
    public R patientMake(@ApiParam(name="appRegister-为参数名",value = "核酸信息参数--这里写参数描述",required = true)@RequestBody MakeVo makeVo){

        System.out.println("---------------------------------------------");

        Subscribe subscribe = new Subscribe();
        DcPaIdVo dcPaIdVo = new DcPaIdVo();
        String departName = makeVo.getDepartName();
        String dcName = makeVo.getDoctorName();
        String phone = makeVo.getPhone();
        Integer deId = this.makeService.selectDepartmentId(departName);
        Integer dcId = this.makeService.selectDoctorId(dcName);
        Integer paId = this.makeService.selectPatientId(phone);
        dcPaIdVo.setDoctorId(dcId);
        dcPaIdVo.setPatientId(paId);

        this.makeService.insertPaIdAnddcId(dcPaIdVo);

        String medCard = this.makeService.selectPatientmedCard(phone);
        subscribe.setMedcardCard(medCard);
        subscribe.setDepartmentId(deId);
        subscribe.setSubTypeId(makeVo.getBookType());
        subscribe.setTime(makeVo.getTime());
        this.makeService.insertSubscribe(subscribe);

        System.out.println(subscribe);
        return R.ok();
    }
}
